package cruds.accessories;

import java.util.List;

import items.BigStockable;
import items.Service;
import items.Stockable;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.navigation.paging.PagingNavigator;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.data.DataView;
import org.apache.wicket.markup.repeater.data.IDataProvider;
import org.apache.wicket.model.AbstractReadOnlyModel;

import cruds.ParentList;
import cruds.services.ServiceList;
import dataproviders.ServiceDataProvider;
import dataproviders.StockableDataProvider;
import dynamicmenus.AccessoriesMenu;
import dynamicmenus.ServicesMenu;
import home.Home;
import panels.BodyPanel;
import services.StockableService;
import staticmenus.StaticMenu;

@SuppressWarnings("serial")
public class AccessoryList extends ParentList<Stockable>{

	public AccessoryList(Home home, List<Stockable> stockables) {
		super(home,stockables);
	}


	@Override
	protected void doUpdateAndRedirect(AjaxRequestTarget target,Item<Stockable> item) {
		CrudModifyAccessory panel = new CrudModifyAccessory(this.getHome(),item.getModelObject());
		panel.changePanel(target);
	}

	@Override
	protected void doDeleteAndRedirect(AjaxRequestTarget target, Item<Stockable> item) {
		Stockable accessory = item.getModelObject();
		this.getService().delete(accessory);
		StockableService service = ((StockableService)this.getService());
		AccessoryList listar = new AccessoryList(this.getHome(),service.searchAccessories(accessory.getName()));
		listar.changePanel(target);
	}


	@Override
	protected void createFormFields(Item<Stockable> item) {
		item.add(new Label("brand",item.getModelObject().getBrand()));
		item.add(new Label("model",item.getModelObject().getModel()));
		item.add(new Label("measure",item.getModelObject().getMeasure()));
		item.add(new Label("listprice",String.valueOf(item.getModelObject().getListPrice())));
		item.add(new Label("buyprice",String.valueOf(item.getModelObject().purchasePrice())));
		item.add(new Label("sellprice",String.valueOf(item.getModelObject().salePrice())));
		item.add(new Label("stock",String.valueOf(item.getModelObject().getStock())));
	}


	@Override
	protected void initializeService() {
		this.setService(this.getHome().getGeneralService().getStockableSer());
	}


	@Override
	protected IDataProvider setDataProvider() {
		return new StockableDataProvider(this.getItems());
	}


	@Override
	protected void updateDynamicMenu(AjaxRequestTarget target) {
		AccessoriesMenu menu = new AccessoriesMenu(this.getHome());
		menu.changePanel(target);
		
	}


	@Override
	protected void initializePanelTH(Form form) {
		form.add(new AccListTH());
	}

	


}
